package org.stvd.common.security.support;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.stvd.entities.admin.UserBase;
import org.stvd.entities.admin.Users;

public class UserDetail implements UserDetails {

    private static final long serialVersionUID = -4460517428255724742L;
    
    private Users users = null;
    private UserBase userBase = null;
    private Date loginTime = null;
    private String ipAddress = "";
    private String macAddress = "";
    private String hostName = "";
    private String message = "";
    private String sn = "-1"; // 功能模块序列号：如：菜单编号
    private List<String> parentDepidList = new ArrayList<String>();
    protected List<GrantedAuthority> grantedAuthorities = new ArrayList<>();
    protected boolean enables = true;
    protected boolean accountNonExpired = true;
    protected boolean credentialsNonExpired = true;
    protected boolean accountNonLocked = true;
    protected String password = "";
    
    private Map<String ,Object> remarks = new HashMap<String,Object>();

    public UserDetail(String username, String password, boolean enabled, boolean accountNonExpired,
            boolean credentialsNonExpired, boolean accountNonLocked,
            List<GrantedAuthority> authorities) {

        this.enables = enabled;
        this.accountNonExpired = accountNonExpired;
        this.credentialsNonExpired = credentialsNonExpired;
        this.accountNonLocked = accountNonLocked;
        this.grantedAuthorities = authorities;
        this.password = password;
    }

    public Users getUsers() {
        return users;
    }

    public void setUsers(Users users) {
        this.users = users;
    }

    public Date getLoginTime() {
        return loginTime;
    }

    public void setLoginTime(Date loginTime) {
        this.loginTime = loginTime;
    }

    public String getIpAddress() {
        return ipAddress;
    }

    public void setIpAddress(String ipAddress) {
        this.ipAddress = ipAddress;
    }

    public String getMacAddress() {
        return macAddress;
    }

    public void setMacAddress(String macAddress) {
        this.macAddress = macAddress;
    }

    public String getHostName() {
        return hostName;
    }

    public void setHostName(String hostName) {
        this.hostName = hostName;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public List<String> getParentDepidList() {
        return parentDepidList;
    }

    public void setParentDepidList(List<String> parentDepidList) {
        this.parentDepidList = parentDepidList;
    }

    public UserBase getUserBase() {
        return userBase;
    }

    public void setUserBase(UserBase userBase) {
        this.userBase = userBase;
    }

	public Map<String, Object> getRemarks() {
        return remarks;
    }

    public void setRemarks(Map<String, Object> remarks) {
        this.remarks = remarks;
    }
    
    public String getSn() {
        return sn;
    }

    public void setSn(String sn) {
        this.sn = sn;
    }

    @Override
    public Collection<GrantedAuthority> getAuthorities() {
        return this.grantedAuthorities;
    }

    public void setAuthorities(List<GrantedAuthority> authorities) {
        this.grantedAuthorities = authorities ;
    }
    
    @Override
    public String getPassword() {
        return users.getPwd();
    }

    @Override
    public String getUsername() {
        return users.getUserId();
    }

    @Override
    public boolean isAccountNonExpired() {
        return this.accountNonExpired;
    }

    @Override
    public boolean isAccountNonLocked() {
        return this.accountNonLocked;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return this.credentialsNonExpired;
    }

    @Override
    public boolean isEnabled() {
        return this.enables;
    }
}
